/**
 * Search controller
 */

package edu.gatech.oad.doctorsorder;

import java.util.ArrayList;
import java.util.List;

import edu.gatech.oad.user.User;

/**
 * Controller to perform search task
 * 
 * @author chen
 * @version 1.0
 * 
 */
public class SearchController {

	/**
	 * list of users available
	 */
	private final List<User> usrList;

	/**
	 * @param usrList
	 *            list of users available
	 */
	public SearchController(List<User> usrList) {
		this.usrList = usrList;

	}

	/**
	 * Searches all user with the specified name.
	 * 
	 * @param searchName
	 *            the name to search for
	 * @return list of user with the specified name.
	 */
	public List<User> search(String searchName) {
		final List<User> returnList = new ArrayList<User>();

		if (!searchName.trim().equals("")) {
			for (User tmp : usrList) {
				if (tmp.getName().toLowerCase()
						.contains(searchName.trim().toLowerCase())) {
					returnList.add(tmp);
				}
			}
		}
		return returnList;
	}

	/**
	 * To string method.
	 * 
	 * @return string search controller
	 */
	@Override
	public String toString() {

		return super.toString() + "search controller";
	}

}
